// sv_sp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
using namespace std;

struct Link
{
	int x;
	struct Link*next;
} *head,*end;

Link *creat(int n)
{Link *head,*end ;
	if (n)head=new Link;
	head->x=n;
	end=head;
	n--;
	while (n>0)
	{
		end->next=new Link;
		end=end->next;
		end->x=n;
		end->next=NULL;
		n--;
	}
	return head;
}
Link *creat_unsort(int n)
{Link *head,*end ;
srand((unsigned) time(NULL));
	if (n)head=new Link;
	head->x=n;
	end=head;
	n--;
	while (n>0)
	{
		end->next=new Link;
		end=end->next;
		end->x=rand()%n;
		end->next=NULL;
		n--;
	}
	return head;
}


void print(Link *end)
{
	while (end->next)
	{
		cout<<end->x<<'\t';
	//printf("%d\n",end->x);
	end=end->next;
	}
	cout<<end->x;
}

void add(Link *head, int x, int y)
{Link *v,*p=head;
while (p->next)
{
	if (p->x==y)
	{
		v=new struct Link;
		v->x=x;
		v->next=p->next;
		p->next=v;
		return;
	}
	else p=p->next;
}
}

int count(struct Link *head, int k)
{struct Link*pr=head;
	while (pr)
	{k++;
	pr=pr->next;
	}
	return k;
	}

/*int access(struct Link *head, int i)
{
struct Link *point=head;
	while(i)
	{
		i--;
		point=point->next;
	}
return point;
}*/

struct Link *del(Link *b,int x)
{
	Link *d;
if (b->x==x)
{
	d=b;
	b=b->next;
	delete d;
	return b;
}
Link *p=b;
while (p->next)
{
	if (p->next->x==x)
	{
		d=p->next;
		p->next=p->next->next;
		delete d;
		return b;
	}
	p=p->next;
}
return b;
}

int main()
{
	{
	struct Link *head;*end;
	int n,x,y,m,i;
	//struct Link *ipointer;
	m=0;
	//printf("vvedite n");
	//scanf("%d",&n);
	cin>>n;
	cin>>x;
	cin>>y;
	printf("vvedite iscomoe pole");
	cin>>i;
	head=creat(n);
	//ipointer=access(head,i);
	m=count(head,m);
	printf("%d\n",m);
	//printf("%d\n", ipointer);
	add(head,x,y);
	print(head);
	printf("\n");
	m=0;
	m=count(head,m);
	printf("%d\n",m);
	del(head,y);
	print(head);
	printf("\n");
	m=0;
	m=count(head,m);
	printf("%d\n",m);
		//getch();
}
	return 0;
}
